<!DOCTYPE html>
<html>
	{include file="public/_header" /}
	<script type="text/javascript" src="__STATIC__/kindeditor/kindeditor-all-min.js"></script>
	<body>
		<div class="layui-fluid">
			<div class="layui-row layui-col-space15">
				<div class="layui-col-md12">
					<div class="layui-card">
						<div class="layui-card-body ">
							<form class="layui-form" action="">
								<div class="layui-form-item">
									<label class="layui-form-label">模型名称</label>
									<div class="layui-input-block">
										<input type="text" name="name" required lay-verify="required" placeholder="[必填] 中文/名称" autocomplete="off"
										 class="layui-input">
									</div>
								</div>
								<div class="layui-form-item">
									<label class="layui-form-label">模型表键名</label>
									<div class="layui-input-block">
										<input type="text" name="table_name" required lay-verify="required|varVerify" placeholder="[必填] 必须是英文/名称" autocomplete="off"
										 class="layui-input">
									</div>
								</div>
								<div class="layui-form-item">
									<label class="layui-form-label">排序</label>
									<div class="layui-input-block">
										<input type="number" name="sort" value="100" required lay-verify="required" placeholder="排序" autocomplete="off"
										 class="layui-input">
									</div>
								</div>
								<div class="layui-form-item layui-form-text">
									<label class="layui-form-label">描述</label>
									<div class="layui-input-block">
										<input type="text" name="description" value="" required lay-verify="required" placeholder="描述" autocomplete="off"
										 class="layui-input">
									</div>
								</div>
								<div class="layui-form-item">
									<label class="layui-form-label">显示</label>
									<div class="layui-input-block">
										<input type="checkbox" id="status" name="status" lay-filter="switchTest" lay-skin="switch" lay-text="显示|隐藏" checked>
									</div>
								</div>
								<div class="layui-form-item">
									<label class="layui-form-label">单页模型</label>
									<div class="layui-input-block">
										<input type="checkbox" id="ispage" name="ispage" lay-filter="switchTest" lay-skin="switch" lay-text="是|否">
									</div>
								</div>
								<div class="layui-form-item">
									<div class="layui-input-block">
										<button class="layui-btn" lay-submit lay-filter="formDemo">立即提交</button>
										<button type="reset" class="layui-btn layui-btn-primary">重置</button>
									</div>
								</div>
							</form>
						</div>
					</div>
				</div>
			</div>
		</div>
		<style type="text/css">
			.layui-upload-list {
				margin: 0 !important;
				float: left;
			}

			.layui-upload-img {
				width: 45px;
				height: 38px;
				margin: 0 10px;
				border: 1px solid #ddd
			}
		</style>
		<script type="text/javascript">
			$(function() {
			
				layui.use(['form', 'upload'], function() {
					var form = layui.form;
					var $ = layui.jquery;
					form.verify({
					  varVerify: function(value, item){ //value：表单的值、item：表单的DOM对象
					    if(!new RegExp("^[a-zA-Z]([-_a-zA-Z0-9]{3,20})$").test(value)){
					      return '必须以字母开头的3-20位英文字符串';
					    }
					  }
					}); 
					//监听提交
					form.on('submit(formDemo)', function(obj) {
						if (obj.field.status) {
							obj.field.status = 1
						} else {
							obj.field.status = 0
						}
						if (obj.field.ispage) {
							obj.field.ispage = 1
						} else {
							obj.field.ispage = 0
						}
						var index = parent.layer.getFrameIndex(window.name);
						var lfc = top.layerFrameConfig;
						var info = lfc.iframeB.info;
						console.log(obj.field)
						$.post("{:url('admin/Mould/add')}", obj.field, function(res) {
							if (res.status == 1) {
								layer.msg('添加成功', {
									icon: 1,
									time: 300
								}, function() {
									parent.layer.close(index); //再执行关闭
									info.reload()
								});

							} else {
								layer.msg(res.message)
							}
						})
						return false;
					});
				});


			})
		</script>

	</body>
</html>
